<?php
/**
 * Description of ArticleAction
 *
 * @author Alen
 * @since 1.0.0 2014-3-22 by sutroon
 */
class ArticleAction extends ApiAction {
    
    //put your code here
    public function  index(){
        $biz=new SoBizArticle();
        $dataset=$biz->select_arrayset(''.$this->get_paging_sql(), '*');
        if(!$dataset) exit ();
        $count=$biz->select_value('', 'count(SerialNo)');
        echo '{"total":'.$count.',"rows":'.  json_encode($dataset).'}';
        // {"total":"8","rows":[{"id":"76154","firstname":"8","lastname":"8","phone":"8","email":"9@qq.com"},{"id":"76157","firstname":"11","lastname":"dd","phone":"dd","email":"dd@qq.com"},{"id":"76158","firstname":"rer4e","lastname":"rere","phone":"rere","email":""},{"id":"76160","firstname":"hola","lastname":"amigos","phone":"565656565","email":"hola@gmail.com"},{"id":"76162","firstname":"65665","lastname":"5","phone":"565665","email":"ddsssgdfgdgdfgfdgfdgfdgfdgfdgfdgfdgdf@gmail.com"},{"id":"76163","firstname":"jh","lastname":"kjk","phone":"","email":""},{"id":"76164","firstname":"Joe","lastname":"Blogs","phone":"","email":"Joe@blogs.co.uk"},{"id":"76165","firstname":"bgtnhy","lastname":"hun","phone":"0000 ppppppp","email":"info@digggg.com"}]}
    }
    
    public function save(){
        $biz=new SoBizArticle();
        $msg=$biz->save();
        echo $this->get_json_fmt_result($msg);
    }
    public function remove(){        
        $biz=new SoBizArticle();
        $msg=$biz->remove();
        echo $this->get_json_fmt_result($msg);
    }
    public function read_one(){
        $biz=new SoBizArticle();
        $id=request_numeric('id');
        $dataset=$biz->read_one($id);
        if($dataset){
            $arr=array('id'=>$id,'title'=>$dataset['Title'],'content'=>$dataset['Content']);
            echo json_encode($arr);
        }
    }
    public function set_state(){        
        $biz=new SoBizArticle();
        $msg=$biz->update_records('State='.request_numeric('state'), 'ID='.request_numeric('id'));
        echo $this->get_json_fmt_result($msg);
    }
}
